{% extends 'frame.html' %}

{% block right-container %}
    <div class="right-container container container-fluid add-container">
        <form id="formcheck">
            <!-- 目标主机地址-->
            <div class="form-group">
                <label for="hosts">目标主机地址</label>
                <input class="project-path form-control" type="text" placeholder="10.0.0.1;10.0.0.2" id="hosts" name="hosts" required>
            </div>

            <!-- 项目名称 -->
            <div class="form-group">
                <label for="path" class="control-label">项目名称</label>
                <input class="project-path form-control" type="text" placeholder="name" id="proname" name="proname" required>
            </div>

            <!-- 项目路径 -->
            <div class="form-group">
                <label for="path" class="control-label">项目路径</label>
                <input class="project-path form-control" placeholder="项目绝对路径" id="path" name="path" required>
            </div>

            <div class="row">
                <!-- 仓库地址-->
                <div class="form-group col-md-5">
                    <label for="gitaddr">git服务器</label>
                    <select class="form-control select1">
                        {% for m in data %}
                        <option class="serverip">{{ m.ServerIp }}</option>
                        {% endfor %}
                    </select>

                </div>
                <div class="form-group col-md-5">
                    <label for="gitrepo">Git仓库</label>
                    <input class="form-control" placeholder="example.git" id="gitrepo" name="gitrepo" required>
                </div>

            </div>
            <div class="row">
                <!-- 用户名 -->
                <div class="form-group col-md-5">
                    <label for="username">用户名</label>
                    <input class="form-control" placeholder="用户名" id="username" name="username" required>
                </div>

                <!-- 密码 -->
                <div class="form-group col-md-5">
                    <label for="PassWord" >密码</label>
                        <input class="form-control" placeholder="PassWord" type="password" id="PassWord" name="PassWord" required>
                </div>
            </div>
        <!-- 备注-->
            <div class="form-group">
                <label for="content" class="control-label">备注</label>
                    <input class="form-control" placeholder="备注" type="text" id="content" name="content">
            </div>
            <button type="button" class="btn btn-primary savebtn"  id="savebtn">添加项目</button>
        </form>
    </div>

{% endblock %}

{% block customjs %}
    <script type="text/javascript" src="/static/js/jquery.validate.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {

        function valContent() {
            return $("#formcheck").validate({
                rules: {
                    hosts: {
                        required: true
                    },
                    proname: {
                        required: true
                    },
                    path: {
                        required: true
                    },
                    username: {
                        required: true
                    },
                    PassWord: {
                        required: true
                    }
                }
            }).form();
        }
            $(".urltorepo").click(function () {
                var GitAddr = $(this).find(".surl_to_repo").html();
                $("#gitaddr").val(GitAddr);
            });
            $("#savebtn").click(function () {
                if (valContent()) {
                    var Hosts = document.getElementById("hosts").value;
                    var Name = document.getElementById("proname").value;
                    var ProPath = document.getElementById("path").value;
{#                    var GitAddr = document.getElementById("gitaddr").value;#}
                    var GitAddr = $(".select1 option:selected").text();
                    var UserName = document.getElementById("username").value;
                    var Keys = document.getElementById("PassWord").value;
                    var ConTent = document.getElementById("content").value;
                    var GitRepo = document.getElementById("gitrepo").value;
                    $.ajax({
                        url: '/Addpro/',
                        type: 'POST',
                        data: {
                            'Hosts': Hosts,
                            'Name': Name,
                            'ProPath': ProPath,
                            'GitAddr': GitAddr,
                            'GitRepo': GitRepo,
                            'UserName': UserName,
                            'Keys': Keys,
                            'ConTent': ConTent
                        },
                        success: function (result) {
                            alert("添加成功" + result);
                            window.location.reload();
                        },
                        error: function (result) {
                            alert(result);
                        }
                    });
                }
            });

        });
    </script>
{% endblock %}